package com.example.financecollegeorderdish.vm

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.financecollegeorderdish.db.AppDatabase
import com.example.financecollegeorderdish.db.bean.DishBean
import com.quyunshuo.androidbaseframemvvm.base.mvvm.vm.BaseViewModel
import com.wuhao.lib_base.BaseApplication.context
import com.wuhao.lib_common.utils.LoggerHelper
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.functions.Consumer
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class MainViewModel() : BaseViewModel() {
    val dao = AppDatabase.getInstance(context).dishBeanDao()
    var tasteList = dao.getTasteList()
    var healthList = dao.queryAll()

    //网络状态实时监听
    private var _mainRvValue= MutableLiveData<List<DishBean>>()

    var mainRvList: LiveData<List<DishBean>> = _mainRvValue

    //改变网络状态
    fun changeMainRvData(newData: List<DishBean>) {
        _mainRvValue.value = newData
//        CoroutineScope(Dispatchers.IO)
//            .launch {
//                if (tasteList.isEmpty()) {
//                    val queryAllNoLive = dao.queryAllNoLive()
//                    mainRvValue=queryAllNoLive
//
////                    withContext(Dispatchers.Main) {
////                        LoggerHelper.e("1")
////                        mainRvValue.value = queryAllNoLive
////                    }
//                } else {
//                    val queryByCondition = dao.queryByCondition(tasteList)
//                    mainRvValue=queryByCondition
////                    withContext(Dispatchers.Main) {
////                        LoggerHelper.e("1")
////                        mainRvValue.value = queryByCondition
////                    }
//                }
//            }
//        viewModelScope.launch(Dispatchers.IO) {
//
//        }
    }
}